package sctl;

import java.util.*;
import java.io.*;
import java.math.BigDecimal;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class Driver 
{
	
	public static void main(String[] args)
	{
		Configuration config = new Configuration();
		SessionFactory sessionFactory = config.configure().buildSessionFactory();
		String fileName = "C:/Documents and Settings/khawkins/Desktop/SCTL-WORKSPACE/SCTL-NORM/results-sctl.csv";
		Map<String, Question> questions = new TreeMap<String, Question>();
		long startTime = System.currentTimeMillis();
		
		for(int i = 1; i<=22; i++)
		{
			questions.put("Q"+i, new Question("Q"+i));
			
		}
		
		System.out.println("System initialized. Questions and CDFs created.");
		
		try
		{
			BufferedReader reader = new BufferedReader(new FileReader(fileName));
			String strLine = null;
			StringTokenizer st = null;
			
			while((strLine = reader.readLine()) != null)
			{
				st = new StringTokenizer(strLine, ",");
				while(st.hasMoreTokens())
				{
					String questionString = st.nextToken();
					Question question = questions.get(questionString);		
					String nString = st.nextToken();					
					CUM_DENS_FUNC cdf = question.getCDF(nString);
					BigDecimal probability = new BigDecimal(st.nextToken());
					BigDecimal value = new BigDecimal(st.nextToken());
					cdf.addTUPLE(new Tuple(probability, value));		
																									
				}				
			}
		}
		catch(FileNotFoundException e) 
		{	
			e.printStackTrace();
		}
		catch(IOException e) 
		{
			e.printStackTrace();
		}
		
		System.out.println("Success importing!");				
		System.out.println("Beginning reordering!");
		
		for(int q = 1; q<=22; q++)
		{
			System.out.println(questions.get("Q"+q).printCDFs());
		}
		
		System.out.println("Program Complete!");
		long endTime = System.currentTimeMillis();
		long result = endTime - startTime;
		System.out.println("The program took " +result + " milliseconds to complete!" );
	}

}
